home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
c
/
recio202.zip
/
rcbput.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-05-05
|
4KB
|
107 lines
/*****************************************************************************
MODULE: rcbput.c
PURPOSE: recio column delimited integral number output functions
COPYRIGHT: (C) 1994 William Pierpoint
COMPILER: Borland C Version 3.1
OS: MSDOS Version 6.2
VERSION: 2.02
RELEASE: May 5, 1994
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "recio.h"
extern int _rstatus(REC *rp, int mode);
extern int _rputc(REC *rp, int ch);
#define rfp(rp) ((rp)->r_fp)
#define rcol(rp) ((rp)->r_colno)
#define rfldch(rp) ((rp)->r_fldch)
#define uint unsigned int
#define ulong unsigned long
#define UNSIGNED 0
#define SIGNED 1
/****************************************************************************/
static int /* return error (0=no error; !0=error) */
_rcbputl( /* put integral number to col delim rec stream */
REC *rp, /* pointer to record stream */
size_t begcol, /* field inclusive beginning column */
size_t endcol, /* field inclusive ending column */
int base, /* base (radix) (2 to 36) */
int sign, /* signed number? */
long num) /* number to put to stream */
/****************************************************************************/
{
int err=EOF; /* return error (0=no error; !0=error) */
size_t sl; /* length of _r_nsbuf */
if (!_rstatus(rp, R_WRITE)) {
if (endcol>=begcol && begcol>=rcolno(rp) && base>=2 && base<=36) {
rfldno(rp)++;
/* if colno < begcol, pad with spaces */
while (rcolno(rp) < begcol) {
err = _rputc(rp, ' ');
if (err) goto done;
}
if (sign) {
ltoa(num, _r_nsbuf, base);
} else {
ultoa((ulong)num, _r_nsbuf, base);
}
sl = strlen(_r_nsbuf);
/* if converted string fits space */
if (sl <= (endcol-begcol+1)) {
while (rcolno(rp) <= endcol-sl) {
err = _rputc(rp, ' ');
if (err) goto done;
}
err = fputs(_r_nsbuf, rfp(rp));
if (err==EOF) {
rseterr(rp, R_ENOPUT);
} else {
rcol(rp) += sl;
err = 0;
}
/* else converted string too long for space */
} else {
rsetwarn(rp, R_WWIDTH);
while (rcolno(rp) <= endcol) {
err = _rputc(rp, '*');
}
}
} else {
rseterr(rp, R_EINVAL);
}
}
done:
return err;
}
/****************************************************************************/
/* column delimited integral number output functions */
/****************************************************************************/
int rcbputi(REC *rp, size_t begcol, size_t endcol, int base, int num)
{
return _rcbputl(rp, begcol, endcol, base, SIGNED, (long) num);
}
int rcbputui(REC *rp, size_t begcol, size_t endcol, int base, uint num)
{
return _rcbputl(rp, begcol, endcol, base, UNSIGNED, (long) num);
}
int rcbputl(REC *rp, size_t begcol, size_t endcol, int base, long num)
{
return _rcbputl(rp, begcol, endcol, base, SIGNED, num);
}
int rcbputul(REC *rp, size_t begcol, size_t endcol, int base, ulong num)
{
return _rcbputl(rp, begcol, endcol, base, UNSIGNED, (long) num);
}